<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/content/themes/gray/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/content/themes/icon/icon.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/content/css/Index.css" />
<script src="${pageContext.request.contextPath}/script/Jquery/jquery-1.11.0.min.js"></script>
<script src="${pageContext.request.contextPath}/script/Easyui/jquery.easyui.min.js"></script>
<script src="${pageContext.request.contextPath}/script/Easyui/easyui-lang-zh_CN.js"></script>
<script src="${pageContext.request.contextPath}/script/Common/utils.js"></script>
<script src="${pageContext.request.contextPath}/script/Common/common.js"></script>
<script src="${pageContext.request.contextPath}/script/Common/index.js"></script>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生信息表</title>
<script type="text/javascript">
	$(function() {
		var TypeofTraining = [
		          		    {TypeTrainId:'请选择',name:'请选择'},                    
		          		    {TypeTrainId:'学硕',name:'学硕'},
		          		    {TypeTrainId:'专硕',name:'专硕'},
		          		           		     ];
		          	    var Cultivate = [
		          		    {CultivateId:'请选择',name:'请选择'},
		          		    {CultivateId:'机械工程',name:'机械工程'},
		          		    {CultivateId:'工业工程',name:'工业工程'},
		          		           		];
		          		var Level = [
		          		    {LevelId:'请选择',name:'请选择'},
		          		    {LevelId:'硕士',name:'硕士'},
		          		    {LevelId:'博士',name:'博士'},
		          		           		];
		          	    var Graduation = [
		          		    {GraduationId:'请选择',name:'请选择'},
		          		    {GraduationId:'企业',name:'企业'},
		          		    {GraduationId:'高校',name:'高校'},
		          		           		 ];
		          		var Gender = [
		          		    {GenderId:'男',name:'男'},
		          		    {GenderId:'女',name:'女'},
		          		           	 ];
		          		$("#tbList").datagrid({
		          			url : 'StudentListServlet',
		          			loadMsg : '数据加载中请稍后……',
		          			pagination : true,
		          			rownumbers : true,
		          			idField : "ID",
		          			lines : true,
		          			columns : [ [ {
		          				field : 'Name',
		          				title : '学生姓名',
		          				sortable : true,
		          				width : 100,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			},{
		          				field : 'StudentID',
		          				title : '学号',
		          				sortable : true,
		          				width : 100,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			}, {
		          				field : 'Gender',
		          				title : '性别',
		          				sortable : true,
		          				width : 100,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          				editor: {  
		          	            type: 'combobox',  
		          	            options: {  
		          	            data: Gender,  
		          	            valueField: 'GenderId',  
		          	            textField: 'name',  
		          	            panelHeight:"auto",
		          	                    }  
		          	                } 
		          			}, {
		          				field : 'Birthday',
		          				title : '出生日期',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:{
		          				type:'datebox',
		          				options:{
		          				required:true
		          					}
		          				}
		          			}, {
		          				field : 'NativePlace',
		          				title : '籍贯',
		          				align : 'center',
		          				editor:'textbox',
		          			}, {
		          				field : 'Tel',
		          				title : '电话',
		          				sortable : true,
		          				width : 100,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			}, {
		          				field : 'Email',
		          				title : 'E-mail',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			}, {
		          				field : 'QQ',
		          				title : 'QQ',
		          				width : 80,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			}, {
		          				field : 'StartYear',
		          				title : '入学年份',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:{
			          				type:'datebox',
			          				options:{
			          				required:true
			          					}
			          				}
		          			}, {
		          				field : 'GraduationYear',
		          				title : '毕业年份',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:{
			          				type:'datebox',
			          				options:{
			          					required:true
			          					}
			          				}
		          			}, {
		          				field : 'TypeTrain',
		          				title : '培养类型',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          			    editor: {  
		                          type: 'combobox',  
		                          options: {  
		                          data: TypeofTraining,  
		                          valueField: 'TypeTrainId',  
		                          textField: 'name',  
		                          panelHeight:"auto",
		                              }  
		                          } 
		          			}, {
		          				field : 'Instructor',
		          				title : '指导老师',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:'textbox',
		          				required:true,
		          			}, {
		          				field : 'GraSource',
		          				title : '本科生源',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:'textbox',
		          			}, {
		          				field : 'Cultivate',
		          				title : '培养专业',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor: {  
		          	            type: 'combobox',  
		          	            options: {  
		          	            data: Cultivate,  
		          	            valueField: 'CultivateId',  
		          	            textField: 'name',               
		          	            required:true,
		          	            panelHeight:"auto",
		          	                    }  
		          	                } 
		          			}, {
		          				field : 'level',
		          				title : '级别',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor: {  
		                          type: 'combobox',  
		                          options: {  
		                          data: Level,  
		                          valueField: 'LevelId',  
		                          textField: 'name',  
		                          required:true,
		                          panelHeight:"auto",
		                              }  
		                          } 
		          			}, {
		          				field : 'Graduation',
		          				title : '毕业去向',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor: {  
		          	            type: 'combobox',  
		          	            options: {  
		          	            data: Graduation,  
		          	            valueField: 'GraduationId',  
		          	            textField: 'name',  
		          	            panelHeight:"auto",
		          	                    }  
		          	                } 
		          			}, {
		          				field : 'Job',
		          				title : '就职单位',
		          				sortable : true,
		          				width : 80,
		          				align : "center",
		          				editor:'textbox',
		          			} ] ],
			singleSelect : true,
			pageSize : 20,
			pageList : [ 20, 50 ],
			striped : true,
			//结束编辑触发
			onAfterEdit: function (rowIndex, rowData, changes) {
                if (editAction == "edit") {
                  	$.post('StudentListServlet', {
                  		method:"edit",
                  		Id:rowData.Id,
                  		Name:rowData.Name,
                  		StudentID:rowData.StudentID,
                  		Gender:rowData.Gender,
                  		Birthday:rowData.Birthday,
                  		NativePlace:rowData.NativePlace,
                  		Tel:rowData.Tel,
                  		Email:rowData.Email,
                  		QQ:rowData.QQ,
                  		StartYear:rowData.StartYear,
                  		GraduationYear:rowData.GraduationYear,
                  		TypeTrain:rowData.TypeTrain,
                  		Instructor:rowData.Instructor,
                  		GraSource:rowData.GraSource,
                  		Cultivate:rowData.Cultivate,
                  		level:rowData.level,
                  		Graduation:rowData.Graduation,
                  		Job:rowData.Job,
                  		},
                  		function(data,textStatus,xhr){
                   			$("#tbList").datagrid("reload");
                   		}
                  	);	
                }  editRow = undefined;
            }, onCancelEdit: function (rowIndex, rowData) {
                $("#tbList").datagrid("rejectChanges");
            }

		});
	})
</script>
</head>
<body>
<table id="tbList" class="easyui-datagrid" title="学生信息表" style="width: 100%" fit="true" data-options="
				iconCls: 'icon-edit',
				toolbar: '#tb',
				method: 'post',
			">
	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="funcAdd()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="funcEdit()">修改</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="funcRemove()">删除</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="funcSave()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="funcCancel()">取消</a>
		&nbsp;姓名：&nbsp;<input type="text" name="name" id="name" size="10"/><a href="javascript:funcSearch()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		<a href="javascript:void(0)" id="Submit" class="easyui-linkbutton" onclick="funcReload()" data-options="iconCls:'icon-reload',plain:true" onclick="funcReload">重置</a> &nbsp;&nbsp;
	</div>
<script type="text/javascript">
		 editRow = undefined;
	     editAction = undefined;
	     function funcAdd() {
	            //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
	            if (editRow != undefined) {return;}
	            	 $.messager.confirm('确认对话框', '您确定添加信息吗？', function (r) {
	                     if (r) {
	                         top.wrapper.addTab("添加信息", "StudentAddServlet?Method=add");
	                     }
	                 })
	     }
	        
	        function funcEdit() {
	            var row = $('#tbList').datagrid('getSelected');
	            if (row) {
	                if (editRow != undefined) {return;}
	                else {
	                    var index = $("#tbList").datagrid('getRowIndex', row);
	                    //   var index = row.Id;
	                    $("#tbList").datagrid('beginEdit', index);
	                    editAction = "edit";
	                    editRow = index;
	                }
	            }
	            else {
	                com.message("information", "请选中一行");
	            }
	        }
	        function funcRemove() {
	        	if(editRow != undefined){return;}
	            $.messager.confirm('确认对话框', '您确定删除该行吗？', function (r) {
	                if (r) {
	                	editAction = "remove";
	                    var rowData = $("#tbList").datagrid("getSelected");
	                    if (rowData) {
	                    	$.post('StudentListServlet', {
	                    		method:"remove",
	                    		Id:rowData.Id
	                    		},
	                    		function(data,textStatus,xhr){
	                     			$("#tbList").datagrid("reload");
	                     		}
	                    	);	
	                    }
	                }
	            });
	        } 

	        function funcSave() {
	            $('#tbList').datagrid('endEdit', editRow);
	        }
	        function funcCancel() {
	            $('#tbList').datagrid("cancelEdit", editRow);
	            editRow = undefined;
	            editAction = undefined;
	        }
	        
			function funcSearch() {
				$('#tbList').datagrid('load', {
					name : $('#name').val()
				});
			}
			function funcReload(){
				$('#tbList').datagrid('load',{
					name : null
				});
			}
	</script>
	
</body>
</html>